﻿#region Using

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using GameLogic.External;

#endregion

namespace CommunicationLibrary.TransportData
{
    [DataContract(Name = "B", IsReference = true)]
    public class GameState
    {
        public GameState(IGameState state)
        {
            lock (InstanceManager.Instance)
            {
                InstanceManager.Instance.Clear();
                this.Players = state.Players.Select(InstanceManager.Instance.GetOrAddPlayer);
                this.Tiles = state.Tiles.Select(InstanceManager.Instance.GetOrAddTile);
            }
        }

        [DataMember(Name = "A")]
        public IEnumerable<Tile> Tiles { get; private set; }

        [DataMember(Name = "B")]
        public IEnumerable<Player> Players { get; private set; }
    }
}